<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <!-- <el-form-item label="创建时间" prop="gmtCreate">
      <el-input v-model="dataForm.gmtCreate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="gmtModified">
      <el-input v-model="dataForm.gmtModified" placeholder=""></el-input>
    </el-form-item> -->
    <el-form-item label="ImageCode" prop="imageCode">
      <el-input v-model="dataForm.imageCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="图片描述" prop="imageDesc">
      <el-input v-model="dataForm.imageDesc" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="imageStatus">
      <el-input v-model="dataForm.imageStatus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="分类" prop="imageCategory">
      <el-input v-model="dataForm.imageCategory" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="订单ID" prop="orderId">
      <el-input v-model="dataForm.orderId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="尺寸（长）" prop="imageWidth">
      <el-input v-model="dataForm.imageWidth" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="尺寸（宽）" prop="imageHeight">
      <el-input v-model="dataForm.imageHeight" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="生图模型" prop="imageGenMode">
      <el-input v-model="dataForm.imageGenMode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="提示词" prop="imageGenPrompt">
      <el-input v-model="dataForm.imageGenPrompt" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="生成图" prop="imageGenSourceImgurl">
      <el-input v-model="dataForm.imageGenSourceImgurl" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="素材Code" prop="imageGenMaterialCode">
      <el-input v-model="dataForm.imageGenMaterialCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="模板Code" prop="imageGenTemplateCode">
      <el-input v-model="dataForm.imageGenTemplateCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="成品图" prop="creator">
      <el-input v-model="dataForm.creator" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="修改图" prop="modifier">
      <el-input v-model="dataForm.modifier" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="扩展" prop="extInfo">
      <el-input v-model="dataForm.extInfo" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="环境" prop="env">
      <el-input v-model="dataForm.env" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          gmtCreate: '',
          gmtModified: '',
          imageCode: '',
          imageDesc: '',
          imageStatus: '',
          imageCategory: '',
          orderId: '',
          imageWidth: '',
          imageHeight: '',
          imageGenMode: '',
          imageGenPrompt: '',
          imageGenSourceImgUrl: '',
          imageGenMaterialCode: '',
          imageGenTemplateCode: '',
          creator: '',
          modifier: '',
          userId: '',
          extInfo: '',
          env: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageDesc: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageStatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageCategory: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageWidth: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageHeight: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageGenMode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageGenPrompt: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageGenSourceImgUrl: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageGenMaterialCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          imageGenTemplateCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          creator: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifier: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          extInfo: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          env: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/image/image/queryWormholeGalaxyImage`),
              method: 'post',
              data: this.$http.adornData({
                "id":id
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.wmhGalaxyImage.gmtCreate
                this.dataForm.gmtModified = data.wmhGalaxyImage.gmtModified
                this.dataForm.imageCode = data.wmhGalaxyImage.imageCode
                this.dataForm.imageDesc = data.wmhGalaxyImage.imageDesc
                this.dataForm.imageStatus = data.wmhGalaxyImage.imageStatus
                this.dataForm.imageCategory = data.wmhGalaxyImage.imageCategory
                this.dataForm.orderId = data.wmhGalaxyImage.orderId
                this.dataForm.imageWidth = data.wmhGalaxyImage.imageWidth
                this.dataForm.imageHeight = data.wmhGalaxyImage.imageHeight
                this.dataForm.imageGenMode = data.wmhGalaxyImage.imageGenMode
                this.dataForm.imageGenPrompt = data.wmhGalaxyImage.imageGenPrompt
                this.dataForm.imageGenSourceImgUrl = data.wmhGalaxyImage.imageGenSourceImgUrl
                this.dataForm.imageGenMaterialCode = data.wmhGalaxyImage.imageGenMaterialCode
                this.dataForm.imageGenTemplateCode = data.wmhGalaxyImage.imageGenTemplateCode
                this.dataForm.creator = data.wmhGalaxyImage.creator
                this.dataForm.modifier = data.wmhGalaxyImage.modifier
                this.dataForm.userId = data.wmhGalaxyImage.userId
                this.dataForm.extInfo = data.wmhGalaxyImage.extInfo
                this.dataForm.env = data.wmhGalaxyImage.env
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/image/image/${!this.dataForm.id ? 'createWormholeGalaxyImage' : 'createWormholeGalaxyImage'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'gmtModified': this.dataForm.gmtModified,
                'imageCode': this.dataForm.imageCode,
                'imageDesc': this.dataForm.imageDesc,
                'imageStatus': this.dataForm.imageStatus,
                'imageCategory': this.dataForm.imageCategory,
                'orderId': this.dataForm.orderId,
                'imageWidth': this.dataForm.imageWidth,
                'imageHeight': this.dataForm.imageHeight,
                'imageGenMode': this.dataForm.imageGenMode,
                'imageGenPrompt': this.dataForm.imageGenPrompt,
                'imageGenSourceImgUrl': this.dataForm.imageGenSourceImgUrl,
                'imageGenMaterialCode': this.dataForm.imageGenMaterialCode,
                'imageGenTemplateCode': this.dataForm.imageGenTemplateCode,
                'creator': this.dataForm.creator,
                'modifier': this.dataForm.modifier,
                'userId': this.dataForm.userId,
                'extInfo': this.dataForm.extInfo,
                'env': this.dataForm.env
              })
            }).then(({data}) => {
              if (data && data.seccess) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
